/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jaxb;

import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import photogallery.Image;

/**
 *
 * @author ThuanPQ
 */
public class AlbumContentMarshaller {

    private Image[] images;

    public AlbumContentMarshaller() {
    }

    public void createXML(Integer albumId, Image[] entities, String path) {
//        if (entities != null && entities.length > 0) {
        Images en = new Images();
        en.setAlbumId(albumId);
        for (Image entity : entities) {
            en.getImage().add(entity);
        }

        try {
            JAXBContext ctx = JAXBContext.newInstance(en.getClass());
            Marshaller mar = ctx.createMarshaller();
            mar.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
            mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            mar.marshal(en, new File(path + "//album-" + String.valueOf(albumId) + ".xml"));
        } catch (JAXBException ex) {
            ex.printStackTrace();
        }
//        }
    }
}
